package LoginPackage;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.testng.annotations.Test;

import PagePackage.MyPageFactory;
import PagePackage.internalPageClass;
import PagePackage.loginPageClass;
import PagePackage.userContactInfoPageClass;
import PagePackage.userRolePageClass;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import static org.testng.AssertJUnit.*;
import PagePackage.usersPageClass;

public class EditUser extends TestBaseClass {
	
	/*@Test (priority=0)
	 public void AdminEditsUser() {
		
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(adminEmail, adminPassword);
			MyPageFactory.getPage(driver, userRolePageClass.class).clickUserTab()
			.findUser(editEmail)
			.scrollAndClick(0, 0, "//*[text()='"+editEmail+"']")
			.firstName(adminEditsUserfirstName)
			.lastName(adminEditsUserlastName)
			.email(adminEditsUseremail)
			.phone1(adminEditsUserphone1)
			.phone2(adminEditsUserphone2)
			.roleTabClick()
			
			.chooseRole(athleteRole);
		    MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
			MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
			
			.findUser(adminEditsUseremail)
			.scrollAndClick(0, 0, "//*[text()='"+adminEditsUseremail+"']");
			wait.until(visibilityOfElementLocated(By.name("firstName")));
			wait.until(visibilityOfElementLocated(By.name("lastName")));
			driver.manage().timeouts().implicitlyWait(7, TimeUnit.SECONDS);
			driver.manage().timeouts().setScriptTimeout(5,TimeUnit.SECONDS);
		  assertEquals(adminEditsUserfirstName, contactInfo.firstName.getAttribute("value"));
		  assertEquals(adminEditsUserlastName, contactInfo.lastName.getAttribute("value"));
		  assertEquals(adminEditsUseremail, contactInfo.emailField.getAttribute("value"));
		  assertEquals(adminEditsUserphone1, contactInfo.phone1Field.getAttribute("value"));
		  assertEquals(adminEditsUserphone2, contactInfo.phone2Field.getAttribute("value"));
			
			
		  MyPageFactory.getPage(driver, userContactInfoPageClass.class).roleTabClick();
		  wait.until(visibilityOfElementLocated(By.xpath("html/body/div[2]/div/section/div/div/div/div[2]/ul[2]/li[1]/x-krossover-role/div/div[4]/span")));
		  assertEquals(athleteRole, driver.findElement(By.xpath("html/body/div[2]/div/section/div/div/div/div[2]/ul[2]/li[1]/x-krossover-role/div/div[4]/span")).getText());
		  driver.get("https://www-dev.krossover.com/intelligence-qa/schools");
			 MyPageFactory.getPage(driver, internalPageClass.class).logout();		
	*/
	@Test (priority=1)
	 public void SAEditsUser() {
		   
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(saEmail	, saPassword);
			MyPageFactory.getPage(driver, userRolePageClass.class).clickUserTab()
			.findUserByEmail(saEditEmail)
			.scrollAndClick(0, 0, "//*[text()='"+saEditEmail+"']")
			
			.firstName(saEditsUserfirstName)
			.lastName(saEditsUserlastName)
			.email(saEditsUseremail)
			.phone1(saEditsUserphone1)
			.phone2(saEditsUserphone2)
			.roleTabClick()
			
			.chooseRole(athleteRole);
		    MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
			MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
			.findUserByEmail(saEditsUseremail)
			.scrollAndClick(0, 0, "//*[text()='"+saEditsUseremail+"']");
			wait.until(visibilityOfElementLocated(By.name("firstName")));
			wait.until(visibilityOfElementLocated(By.name("lastName")));
			driver.manage().timeouts().implicitlyWait(7, TimeUnit.SECONDS);
			driver.manage().timeouts().setScriptTimeout(5,TimeUnit.SECONDS);
		  assertEquals(saEditsUserfirstName, contactInfo.firstName.getAttribute("value"));
		  assertEquals(saEditsUserlastName, contactInfo.lastName.getAttribute("value"));
		  assertEquals(saEditsUseremail, contactInfo.emailField.getAttribute("value"));
		  assertEquals(saEditsUserphone1, contactInfo.phone1Field.getAttribute("value"));
		  assertEquals(saEditsUserphone2, contactInfo.phone2Field.getAttribute("value"));
			
			
		  MyPageFactory.getPage(driver, userContactInfoPageClass.class).roleTabClick();
		  wait.until(visibilityOfElementLocated(By.xpath("html/body/div[2]/div/section/div/div/div/div[2]/ul[2]/li[1]/x-krossover-role/div/div[4]/span")));
		  assertEquals(athleteRole, driver.findElement(By.xpath("html/body/div[2]/div/section/div/div/div/div[2]/ul[2]/li[1]/x-krossover-role/div/div[4]/span")).getText());
		  driver.get("https://www-dev.krossover.com/intelligence-qa/schools");
			 MyPageFactory.getPage(driver, internalPageClass.class).logout();		 
	}

}
